/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package Rules.impl;

import BoardGame.Field;
import BoardGame.Figure;

import BoardGame.impl.FigureImpl;

import Rules.KW_KingWhite;
import Rules.RulesPackage;

import de.upb.tools.sdm.*;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>KW King White</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public class KW_KingWhiteImpl extends FigureImpl implements KW_KingWhite {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected KW_KingWhiteImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return RulesPackage.Literals.KW_KING_WHITE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void moveTo(Field field) {
		boolean fujaba__Success = false;
		Figure noFigure = null;
		Field field01 = null;
		Field currentField = null;
		Field field02 = null;
		Field field10 = null;
		Field field11 = null;
		Field field00 = null;

		// story pattern 
		try {
			fujaba__Success = false;

			// check object field is really bound
			JavaSDM.ensure(field != null);
			// bind object
			field02 = field.getNeighbourWest();

			// check object field02 is really bound
			JavaSDM.ensure(field02 != null);

			// check isomorphic binding between objects field02 and field
			JavaSDM.ensure(!field02.equals(field));

			// check negative bindings
			try {
				fujaba__Success = false;

				// bind object
				noFigure = field02.getFigure();

				// check object noFigure is really bound
				JavaSDM.ensure(noFigure != null);

				// check isomorphic binding between objects noFigure and this
				JavaSDM.ensure(!noFigure.equals(this));

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = !(fujaba__Success);

			JavaSDM.ensure(fujaba__Success);

			// bind object
			currentField = this.getField();

			// check object currentField is really bound
			JavaSDM.ensure(currentField != null);

			// check isomorphic binding between objects field02 and currentField
			JavaSDM.ensure(!field02.equals(currentField));

			// check isomorphic binding between objects field and currentField
			JavaSDM.ensure(!field.equals(currentField));

			// bind object
			field01 = currentField.getNeighbourEast();

			// check object field01 is really bound
			JavaSDM.ensure(field01 != null);

			// check isomorphic binding between objects field01 and currentField
			JavaSDM.ensure(!field01.equals(currentField));

			// check isomorphic binding between objects field02 and field01
			JavaSDM.ensure(!field02.equals(field01));

			// check isomorphic binding between objects field01 and field
			JavaSDM.ensure(!field01.equals(field));

			// check link NeighbourWest from field02 to field01
			JavaSDM.ensure(field01.equals(field02.getNeighbourWest()));

			// check negative bindings
			try {
				fujaba__Success = false;

				// bind object
				noFigure = field01.getFigure();

				// check object noFigure is really bound
				JavaSDM.ensure(noFigure != null);

				// check isomorphic binding between objects noFigure and this
				JavaSDM.ensure(!noFigure.equals(this));

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = !(fujaba__Success);

			JavaSDM.ensure(fujaba__Success);

			// destroy link
			currentField.setFigure(null);
			// create link
			field.setFigure(this);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		if (fujaba__Success) {
			return;

		} else {
			// story pattern 
			try {
				fujaba__Success = false;

				// check object field is really bound
				JavaSDM.ensure(field != null);
				// bind object
				field10 = field.getNeighbourSouth();

				// check object field10 is really bound
				JavaSDM.ensure(field10 != null);

				// check isomorphic binding between objects field10 and field
				JavaSDM.ensure(!field10.equals(field));

				// bind object
				field01 = field.getNeighbourEast();

				// check object field01 is really bound
				JavaSDM.ensure(field01 != null);

				// check isomorphic binding between objects field10 and field01
				JavaSDM.ensure(!field10.equals(field01));

				// check isomorphic binding between objects field01 and field
				JavaSDM.ensure(!field01.equals(field));

				// bind object
				currentField = this.getField();

				// check object currentField is really bound
				JavaSDM.ensure(currentField != null);

				// check isomorphic binding between objects field01 and currentField
				JavaSDM.ensure(!field01.equals(currentField));

				// check isomorphic binding between objects field10 and currentField
				JavaSDM.ensure(!field10.equals(currentField));

				// check isomorphic binding between objects field and currentField
				JavaSDM.ensure(!field.equals(currentField));

				// check link NeighbourWest from currentField to field10
				JavaSDM.ensure(field10.equals(currentField.getNeighbourWest()));

				// destroy link
				currentField.setFigure(null);
				// create link
				field.setFigure(this);

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			if (fujaba__Success) {
				return;

			} else {
				// story pattern 
				try {
					fujaba__Success = false;

					// check object field is really bound
					JavaSDM.ensure(field != null);
					// bind object
					field00 = field.getNeighbourWest();

					// check object field00 is really bound
					JavaSDM.ensure(field00 != null);

					// check isomorphic binding between objects field00 and field
					JavaSDM.ensure(!field00.equals(field));

					// bind object
					currentField = this.getField();

					// check object currentField is really bound
					JavaSDM.ensure(currentField != null);

					// check isomorphic binding between objects field00 and currentField
					JavaSDM.ensure(!field00.equals(currentField));

					// check isomorphic binding between objects field and currentField
					JavaSDM.ensure(!field.equals(currentField));

					// check link NeighbourSouth from currentField to field00
					JavaSDM.ensure(field00.equals(currentField
							.getNeighbourNorth()));

					// bind object
					field11 = currentField.getNeighbourEast();

					// check object field11 is really bound
					JavaSDM.ensure(field11 != null);

					// check isomorphic binding between objects field11 and currentField
					JavaSDM.ensure(!field11.equals(currentField));

					// check isomorphic binding between objects field11 and field00
					JavaSDM.ensure(!field11.equals(field00));

					// check isomorphic binding between objects field11 and field
					JavaSDM.ensure(!field11.equals(field));

					// destroy link
					currentField.setFigure(null);
					// create link
					field.setFigure(this);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}

				if (fujaba__Success) {
					return;

				} else {
					// story pattern 
					try {
						fujaba__Success = false;

						// check object field is really bound
						JavaSDM.ensure(field != null);
						// bind object
						field10 = field.getNeighbourWest();

						// check object field10 is really bound
						JavaSDM.ensure(field10 != null);

						// check isomorphic binding between objects field10 and field
						JavaSDM.ensure(!field10.equals(field));

						// bind object
						currentField = this.getField();

						// check object currentField is really bound
						JavaSDM.ensure(currentField != null);

						// check isomorphic binding between objects field10 and currentField
						JavaSDM.ensure(!field10.equals(currentField));

						// check isomorphic binding between objects field and currentField
						JavaSDM.ensure(!field.equals(currentField));

						// check link NeighbourSouth from field10 to currentField
						JavaSDM.ensure(currentField.equals(field10
								.getNeighbourNorth()));

						// bind object
						field01 = currentField.getNeighbourEast();

						// check object field01 is really bound
						JavaSDM.ensure(field01 != null);

						// check isomorphic binding between objects field01 and currentField
						JavaSDM.ensure(!field01.equals(currentField));

						// check isomorphic binding between objects field10 and field01
						JavaSDM.ensure(!field10.equals(field01));

						// check isomorphic binding between objects field01 and field
						JavaSDM.ensure(!field01.equals(field));

						// destroy link
						currentField.setFigure(null);
						// create link
						field.setFigure(this);

						fujaba__Success = true;
					} catch (JavaSDMException fujaba__InternalException) {
						fujaba__Success = false;
					}

					if (fujaba__Success) {
						return;

					} else {
						// story pattern 
						try {
							fujaba__Success = false;

							// check object field is really bound
							JavaSDM.ensure(field != null);
							// bind object
							field00 = field.getNeighbourNorth();

							// check object field00 is really bound
							JavaSDM.ensure(field00 != null);

							// check isomorphic binding between objects field00 and field
							JavaSDM.ensure(!field00.equals(field));

							// bind object
							field11 = field.getNeighbourEast();

							// check object field11 is really bound
							JavaSDM.ensure(field11 != null);

							// check isomorphic binding between objects field11 and field00
							JavaSDM.ensure(!field11.equals(field00));

							// check isomorphic binding between objects field11 and field
							JavaSDM.ensure(!field11.equals(field));

							// bind object
							currentField = this.getField();

							// check object currentField is really bound
							JavaSDM.ensure(currentField != null);

							// check isomorphic binding between objects field00 and currentField
							JavaSDM.ensure(!field00.equals(currentField));

							// check isomorphic binding between objects field11 and currentField
							JavaSDM.ensure(!field11.equals(currentField));

							// check isomorphic binding between objects field and currentField
							JavaSDM.ensure(!field.equals(currentField));

							// check link NeighbourWest from currentField to field00
							JavaSDM.ensure(field00.equals(currentField
									.getNeighbourWest()));

							// destroy link
							currentField.setFigure(null);
							// create link
							field.setFigure(this);

							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						if (fujaba__Success) {
							return;

						} else {
							// story pattern 
							try {
								fujaba__Success = false;

								// check object field is really bound
								JavaSDM.ensure(field != null);
								// bind object
								currentField = field.getNeighbourNorth();

								// check object currentField is really bound
								JavaSDM.ensure(currentField != null);

								// check isomorphic binding between objects field and currentField
								JavaSDM.ensure(!field.equals(currentField));

								// check link figure from currentField to this
								JavaSDM.ensure(this.equals(currentField
										.getFigure()));

								// destroy link
								currentField.setFigure(null);
								// create link
								field.setFigure(this);

								fujaba__Success = true;
							} catch (JavaSDMException fujaba__InternalException) {
								fujaba__Success = false;
							}

							if (fujaba__Success) {
								return;

							} else {
								// story pattern 
								try {
									fujaba__Success = false;

									// check object field is really bound
									JavaSDM.ensure(field != null);
									// bind object
									currentField = field.getNeighbourEast();

									// check object currentField is really bound
									JavaSDM.ensure(currentField != null);

									// check isomorphic binding between objects field and currentField
									JavaSDM.ensure(!field.equals(currentField));

									// check link figure from currentField to this
									JavaSDM.ensure(this.equals(currentField
											.getFigure()));

									// destroy link
									currentField.setFigure(null);
									// create link
									field.setFigure(this);

									fujaba__Success = true;
								} catch (JavaSDMException fujaba__InternalException) {
									fujaba__Success = false;
								}

								if (fujaba__Success) {
									return;

								} else {
									// story pattern 
									try {
										fujaba__Success = false;

										// check object field is really bound
										JavaSDM.ensure(field != null);
										// bind object
										currentField = field.getNeighbourWest();

										// check object currentField is really bound
										JavaSDM.ensure(currentField != null);

										// check isomorphic binding between objects field and currentField
										JavaSDM.ensure(!field
												.equals(currentField));

										// check link figure from currentField to this
										JavaSDM.ensure(this.equals(currentField
												.getFigure()));

										// destroy link
										currentField.setFigure(null);
										// create link
										field.setFigure(this);

										fujaba__Success = true;
									} catch (JavaSDMException fujaba__InternalException) {
										fujaba__Success = false;
									}

									if (fujaba__Success) {
										return;

									} else {
										// story pattern 
										try {
											fujaba__Success = false;

											// check object field is really bound
											JavaSDM.ensure(field != null);
											// bind object
											currentField = field
													.getNeighbourSouth();

											// check object currentField is really bound
											JavaSDM.ensure(currentField != null);

											// check isomorphic binding between objects field and currentField
											JavaSDM.ensure(!field
													.equals(currentField));

											// check link figure from currentField to this
											JavaSDM.ensure(this
													.equals(currentField
															.getFigure()));

											// destroy link
											currentField.setFigure(null);
											// create link
											field.setFigure(this);

											fujaba__Success = true;
										} catch (JavaSDMException fujaba__InternalException) {
											fujaba__Success = false;
										}

										if (fujaba__Success) {
											return;

										} else {
											return;

										}

									}

								}

							}

						}

					}

				}

			}

		}
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments)
			throws InvocationTargetException {
		switch (operationID) {
		case RulesPackage.KW_KING_WHITE___MOVE_TO__FIELD:
			moveTo((Field) arguments.get(0));
			return null;
		}
		return super.eInvoke(operationID, arguments);
	}

} //KW_KingWhiteImpl
